<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 2018/10/22
 * Time: 15:11
 */

namespace appapi\modules\v0\modules\uesr\controllers;


use common\models\db\User;
use common\rewrite\deepziyu\yii_fast_api\ApiException;
use common\rewrite\deepziyu\yii_fast_api\Controller;

class SetController extends Controller
{
    /**
     * 上传头像
     * @desc get/post
     * @param string $avatar_url 头像url
     * @return array
     * @throws
     * @return int is_success
     */
    public function actionUploadAvatar($avatar_url)
    {
        if (!$avatar_url){
            throw new ApiException(201810221531, "头像url不能为空");
        }
        $r = [
            'is_success' => 0,
        ];
        $user = \Yii::$app->user->identity;
        $user->avatar_url = $avatar_url;
        if ($user->save()){
            $r['is_success'] = 1;
        }
        return $r;
    }
}